package com.example.demo.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.mapper.TestDao;
import com.example.demo.entity.TestEntity;
import com.example.demo.service.TestService;
import com.example.demo.utils.RedisUtil;
import com.example.demo.vo.TestVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Slf4j
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private TestDao testDao;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<TestEntity> getAll() {
        return testDao.getAll();
    }

    @Override
    public TestEntity getOne(int id) {
        return testDao.test(id);
    }

    @Override
    public IPage<TestEntity> selectByPage(Page<TestEntity> page, TestVo condition) {


        return testDao.selectByPage(page, condition);
    }

    @Override
    public Object testPage1(Page<TestEntity> page, TestVo condition) {


        LambdaQueryWrapper<TestEntity> queryWrapper = new LambdaQueryWrapper<>();

        // 根据TestVo中的属性添加条件
        queryWrapper.eq(condition.getId() != null, TestEntity::getId, condition.getId());

        queryWrapper.like(condition.getName() != null, TestEntity::getName, condition.getName());

        // 添加更多条件...

        return testDao.selectPage(page, queryWrapper);


    }

    @Override
    public Object add(TestEntity testEntity) {
        int insert = testDao.insert(testEntity);
        return insert;
    }

    @Override
    public Object update(TestEntity testEntity) {
        TestVo testVo = new TestVo();
        testVo.setId(1);
        LambdaQueryWrapper<TestEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(testVo.getId() != null, TestEntity::getId, testVo.getId());
        int update = testDao.update(testEntity, queryWrapper);
        return update;
    }

    @Override
    public String a() {

        String zipNo = redisUtil.getZipNo();


        return zipNo;
    }


}
